package com.smartbands.manage.controller;

import com.smartbands.common.entity.UserInfo;
import com.smartbands.common.result.Response;
import com.smartbands.manage.service.UserInfoService;
import com.smartbands.manage.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mtf
 * @create 2021-01-28-15:10
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private UserService userService;

    @RequestMapping("/get/{id}")
    @ResponseBody
    public Response get(@PathVariable int id) {
        try {
            log.info("==================进入controller================");
            return Response.createResponseBySuccess("success",userInfoService.getById(id));
        }catch (Exception e){
            return Response.createResponseByError(e.getMessage());
        }

    }

    @RequestMapping("/login")
    @ResponseBody
    public Response loginUser(String userName, String password) {
        try {
            return Response.success(userService.login(userName,password));
        } catch (Exception e) {
            return Response.createResponseByError(e.getMessage());
        }
    }

    @RequestMapping("/register")
    @ResponseBody
    public Response register(String userName, String password) {
        try {
            return Response.success(userService.register(userName,password));
        }catch (Exception e){
            log.error(e.getMessage());
            return Response.createResponseByError(e.getMessage());
        }
    }
}
